{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false,
    "jupyter": {
     "outputs_hidden": false
    },
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [],
   "source": [
    "from gs_quant.common import PayReceive\n",
    "from gs_quant.instrument import IRSwap\n",
    "from gs_quant.markets import HistoricalPricingContext\n",
    "from gs_quant.session import Environment, GsSession\n",
    "\n",
    "import datetime as dt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# external users should substitute their client id and secret\n",
    "GsSession.use(Environment.PROD, client_id=None, client_secret=None, scopes=('run_analytics',))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* Calling the `resolve()` method will resolve any relative parameters to absolute values and fill in unspecified parameters.\n",
    "* `resolve()` will change the state of the instrument object in place by default unless argument `in_place` is `False`.\n",
    "* `resolve` can be used to \"fix\" the instrument parameters when evaluating pricing & risk."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false,
    "jupyter": {
     "outputs_hidden": false
    },
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [],
   "source": [
    "my_swap = IRSwap(PayReceive.Pay, '5y', fixed_rate='atm+30')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "tags": [
     "Instrument - Resolve"
    ]
   },
   "outputs": [],
   "source": [
    "# note fixed_rate and termination_date are resolved to a float and date, respectively\n",
    "my_swap.resolve()\n",
    "my_swap.to_dict()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "If you are resolving under a historical pricing context you will need to set the in_place parameter to False to\n",
    "return a dictionary of the resolved trades on each date in the pricing context."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "tags": [
     "Instrument - Resolve",
     "Contexts - HistoricalPricingContext"
    ]
   },
   "outputs": [],
   "source": [
    "with HistoricalPricingContext(dt.date(2025, 3, 25), dt.date(2025, 3, 27)):\n",
    "    resolved_swaps = my_swap.resolve(in_place=False)\n",
    "\n",
    "resolved_swaps.result()[dt.date(2025, 3, 25)].to_dict()"
   ]
  }
 ],
 "metadata": {
  "celltoolbar": "Tags",
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.5"
  },
  "pycharm": {
   "stem_cell": {
    "cell_type": "raw",
    "metadata": {
     "collapsed": false
    },
    "source": []
   }
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
